package com.yuan.controller;

import com.yuan.base.R;
import com.yuan.entity.param.ChatParam;
import com.yuan.entity.resp.ChatResultVo;
import com.yuan.service.DsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import javax.validation.constraints.NotBlank;


@RestController
@RequestMapping("/api/ds")
@RequiredArgsConstructor
public class DsController {



    ///static String apiKey = "751f679c-6ab1-4cb4-af2e-d9c96209c48a";
    private final DsService dsService;

    // sse 流式返回
    @PostMapping(value = "/completions", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chat(@RequestBody ChatParam chatParam) {
        return dsService.sendChat(chatParam);
    }

    @Operation(summary = "查询某个对话的信息列表")
    @GetMapping("/conversation")
    public R conversation(
           @Parameter(name = "对话 sessionId") @NotBlank(message = "对话 sessionId 不能为空") String sessionId
    ) {
        return dsService.conversation(sessionId);
    }


    @Operation(summary = "查询某个对话的信息列表")
    @GetMapping("/conversationHistory")
    public R conversationHistory(
            @Parameter(name = "对话 deviceId") @NotBlank(message = "对话 deviceId 不能为空") String deviceId
    ) {
        return dsService.conversationHistory(deviceId);
    }

}
